Okay, so today we are going on from functions and we're going to start looking at applying a bit of
our knowledge.
Okay.
So now you know about the basics.
So changing properties you know about variables.
You know about statements loops and also functions.
Um they are the main areas when it comes to the basics of scripting okay.
What we're going to do now is apply those areas to some different and different sections.
Because we've been looking at parts a lot in our examples, because obviously they're quite simple to
do.
Um, we're going to kind of extend out of that and look at other areas.
So today we are going to have another look at local scripts and about the player.
So we did touch on this a bit early on in the course.
So maybe we watch it as a refresher before this, but we're going to go over some other things with
it as well.
Um, primarily um, we looked at how to reference a player in a local script.
We are going to be looking how to do it in a script.
Okay.
So add a script into server script service.
Okay.
I'm going to get rid of the print function by default there.
Okay.
So um, referencing the player in a standard server script, it's actually quite easy.
Okay.
There is a function you can use.
Um, so which, which you, you compared to an event.
So it's an event that you use.
Um, so the event is called player added.
And it is a member of game dot players.
So we'd write game dot players.
Dot player added.
Okay.
And just like how I explained, um, you know, the basics of events, you now need to apply what you
already know to some different cases.
Okay.
And these are one of these cases.
Now this is an event.
So we're going to use the connect function to connect it to our own function.
And we see here we have a parameter here called player we are going to use okay.
And that is it.
So this event will fire whenever a player joins the game.
Okay, so, um, in order to get the player that join the game, we just reference this parameter here.
This parameter will store the player that joined the game.
So we've already referenced the player.
Okay.
And it's reference the character.
Um, you would use your weight function for a couple seconds and then say for example, um, local character
is equal to player dot character.
Okay.
So now we know how to, um, reference the character.
So now we know how to reference the player through a, through a server script.
We also came along to an issue last time, which is that we had to do a bit of a placeholder way of
referencing the character, and you're going to learn the real method now because it actually involves
an event, which is why I couldn't explain it to you last time.
Okay.
Um, so all you need to write is player dot, character added.
Okay.
And, um, what what character added function.
So this character added here is an event of the player.
Okay.
And this will event will fire when the character is added.
Okay.
And obviously we've looked at writing code on connect after events.
But you can also write colon weight.
And what this does is it waits until this event fires.
So this line here will basically wait for the event to fire.
So it will event.
It will wait for the character to be added.
Okay.
So this bit of code here you can use to basically wait until the character is added.
Then you can go ahead and say um, local character is equal to player character.
Okay.
And this is the exact same way that you'd be using it in a local script.
Okay.
Um, you would reference the character, you reference the player using local player, and then you
will be you can use this to wait until the character has been added.
Then go ahead and reference it just so you know when you are referencing it, it does exist.
Okay.
Um, and then anything else really we talked about, um, previously.
Okay.
We talked about the different rig types.
We talked about some of the properties you can change of the player.
Okay.
So this is just a, um, a quick addition to show you, well, one, how to reference players in the
server script and also how to reference the character properly.
Okay.
Um, just make sure though that, um, this will not be doing it for a specific player.
Um, so this this one script will work for each player, whereas for your local scripts you have an
individual local script for that's been kind of get duplicated into each player.
Okay.
So any stuff you're doing here will be done on the server.
So don't try and do things that only that are should be done locally.
So don't try and.
Do guys or add anything in only.
Only that player should be able to see.
In that case you should use local scripts.
Okay?
Usually when you're talking about players you would be using local scripts, but sometimes you might
want to use this as well.
Okay, so just a bit of an introduction to that event okay.
And next lesson we're going to look at a key example using this event all about values and the leaderboard.
So join me in the next lesson when we have a look at that.